<template>
  <t-dialog
    :header="`${row.projectName}-退回`"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    width="40%"
    top="5%"
  >
    <t-form  ref="form" label-align="top" :data="formData" :rules="rules">
      <t-form-item  name="opinion" label="退回意见：">
        <t-textarea  :autosize="{minRows: 5}"
                    v-model="formData.opinion"  placeholder="请输入内容"/>
      </t-form-item>
    </t-form>
    <template #footer>
      <t-button theme="default" @click="closeDialog">取消</t-button>
      <t-button theme="primary" @click="onSubmit()">提交</t-button>
    </template>
  </t-dialog>
</template>

<script>
export default {
  name: "approve-back",
  props: {
    row: Object
  },
  data(){
    return {
      visible: true,
      formData:{
        id: this.row.approveId,
        businessId: this.row.id,
        // businessId: this.row.businessId,
        // approveType: this.row.approveType,
        opinion: '',
        approveStatus: "4",
      },
      rules: {
        opinion: [
          {required: true, message: "退回意见不能为空"}
        ],
      },
    }
  },
  methods:{
    closeDialog() {
      this.$emit("update:visible", false);
    },
    onSubmit() {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {
          const confirmDia = this.$dialog.confirm({
            header: "审批提示",
            body: `是否确认提交？`,
            theme: "warning",
            onConfirm: ({e}) => {
              // this.formData.kjc = this.row.kjc;
              confirmDia.update({
                confirmBtn: {
                  loading: true,
                },
              })
              this.$api.kjxm.approve.reviewApprove(this.formData).then(response => {
                this.$message.success('提交成功');
                this.$emit("reload");
                this.$emit("update:visible", false);
                confirmDia.destroy();
              }).catch((e) => {
                confirmDia.update({
                  confirmBtn: {
                    loading: false,
                  },
                })
                this.$message.error(e.toString());
              });
            },
          })

        }else {
          const firstError = Object.values(validateResult)[0]?.[0]?.message;
          this.$message.error(firstError);
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
